﻿using System.Collections;

namespace h17
{
    public class Solution {
        public bool WordPattern(string pattern, string str) {
            Hashtable map1 = new Hashtable();
            Hashtable map2 = new Hashtable();
            string[] words = str.Split(' ');
            if(words.Length!=pattern.Length)
                return false;
            for(int i=0;i<words.Length;++i)
            {
                if(map1.Contains(words[i])||map2.Contains(pattern[i]))
                {
                    if(map1.Contains(words[i])&&map2.Contains(pattern[i]))
                    {
                        if((char)map1[words[i]]==pattern[i]&&(string)map2[pattern[i]]==words[i])
                            continue;
                    }
                    return false;
                }
                map1.Add(words[i],pattern[i]);
                map2.Add(pattern[i],words[i]);
            }
            return true;
        }
    }
    
}